package com.xiaoran.robot.service.impl;

import com.xiaoran.robot.entity.Plmm;
import com.xiaoran.robot.mapper.PlmmMapper;
import com.xiaoran.robot.service.PlmmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class PlmmServiceImpl implements PlmmService {
    @Autowired
    PlmmMapper mapper;
    @Override
    public void insertList(List<Plmm> plmmList) {
        for (Plmm plmm : plmmList) {
            mapper.insert(plmm);
        }
    }

    private List<Plmm> selectList(){
        return mapper.selectList(null);
    }
    @Override
    public String randomOne() {
        List<Plmm> plmms = selectList();
        int size = plmms.size();
        Random random = new Random();
        int randNum = random.nextInt(size);
        return plmms.get(randNum).getImgurl();
    }
}
